package com.andreamerla.petslife.util;

/**
 * Created by IntelliJ IDEA.
 * User: a.merla
 * Date: 18/07/13
 * Time: 9.23
 */
public enum Response {
    OK("OK", "No errors occurred"),
    ERROR("ERROR", "Generic error"),
    ERROR_DOWNLOADING_KML("ERROR_DOWNLOADING_KML", "Error downloading KML"),
    ERROR_PARSING_KML("ERROR_PARSING_KML", "Error parsing KML"),
    UNKNOWN_ERROR("UNKNOWN_ERROR", "Server-side error: try again"),
    ZERO_RESULTS("ZERO_RESULTS", "Search was successful but returned no results"),
    OVER_QUERY_LIMIT("OVER_QUERY_LIMIT", "You are over your quota"),
    REQUEST_DENIED("REQUEST_DENIED", "Your request was denied, generally because of lack of a sensor parameter"),
    INVALID_REQUEST("INVALID_REQUEST", "A required query parameter is missing"),
    NOT_FOUND("NOT_FOUND", "The referenced location was not found in the Places database");

    /**
     * GOOGLE PLACES STATUS CODES
     * The "status" field within the Place response object contains the status of the request, and may contain debugging information to help you track down why the Place request failed.
     * The "status" field may contain the following values:
     * <p/>
     * FOR PLACE SEARCH
     * OK indicates that no errors occurred; the place was successfully detected and at least one result was returned.
     * ZERO_RESULTS indicates that the search was successful but returned no results. This may occur if the search was passed a latlng in a remote location.
     * OVER_QUERY_LIMIT indicates that you are over your quota.
     * REQUEST_DENIED indicates that your request was denied, generally because of lack of a sensor parameter.
     * INVALID_REQUEST generally indicates that a required query parameter (location or radius) is missing.
     * <p/>
     * FOR PLACE DETAILS
     * OK indicates that no errors occurred; the place was successfully detected and at least one result was returned.
     * UNKNOWN_ERROR indicates a server-side error; trying again may be successful.
     * ZERO_RESULTS indicates that the reference was valid but no longer refers to a valid result. This may occur if the establishment is no longer in business.
     * OVER_QUERY_LIMIT indicates that you are over your quota.
     * REQUEST_DENIED indicates that your request was denied, generally because of lack of a sensor parameter.
     * INVALID_REQUEST generally indicates that the query (reference) is missing.
     * NOT_FOUND indicates that the referenced location was not found in the Places database.
     */

    private final String name;
    private final String description;

    Response(String name, String description) {
        this.name = name;
        this.description = description;
    }

    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

    public static Response getResponseByName(String name) {
        for (Response response : Response.values())
            if (response.getName().equals(name))
                return response;
        return null;
    }
}
